<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css"/>
    <style>
        .layui-form{width: 80%;margin: 0 auto;}
        .layui-input-block{width: 60%;}
    </style>
</head>
<body>
<form class="layui-form" action="" lay-filter="example" id="editForm">
    <div class="layui-row" style="margin-top: 50px;margin-left: 130px">
        <div class="layui-col-md12" >
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" id="userName" name="userName" lay-verify="required" autocomplete="off" placeholder="请输入用户名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input type="text" id="userPwd" name="userPwd" lay-verify="required" autocomplete="off" placeholder="请输入密码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">真实姓名</label>
                <div class="layui-input-block">
                    <input type="text" id="trueName" name="trueName" lay-verify="required" autocomplete="off" placeholder="请输入真实姓名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input type="text" id="email" name="email" lay-verify="required" autocomplete="off" placeholder="请输入邮箱" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机号</label>
                <div class="layui-input-block">
                    <input type="text" id="tel" name="tel" lay-verify="required" autocomplete="off" placeholder="请输入手机号" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否可用</label>
                <div class="layui-input-block" style="width: 30%;">
                    <input type="radio" name="isValid" value="1" title="是" checked="">
                    <input type="radio" name="isValid" value="0" title="否" >
                </div>
            </div>
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;margin-top: 30px;">
        <div class="layui-input-block" style="width: 80%;margin: 0 auto;text-align: center;">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="putIn">提交</button>
<!--            <button type="submit" class="layui-btn" lay-submit="" lay-filter="update" id="update">保存修改</button>-->
        </div>
        <!--        把id输入框设为隐藏-->
        <div class="layui-form-item" hidden>
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <input type="hidden" id="id" name="id" lay-verify="title" autocomplete="off" placeholder="请输入id" class="layui-input">
            </div>
        </div>
    </div>
</form>

<script src="../../layui/layui.js" charset="utf-8"></script>
<script src="../../js/jquery3.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/area.js" type="text/javascript"></script>
<script src="../../js/select.js" type="text/javascript"></script>
<script>

    layui.use(['form'], function(){
        var form = layui.form;
        //判断是增加还是修改
        var myUrl = "";
        if($('#id').val() == ""){
            myUrl = "http://localhost:8080/crm/user/save";
        } else {
            myUrl = "http://localhost:8080/crm/user/update";
        }
        //监听
        form.on('submit(putIn)', function(data){
            layer.alert("恭喜你，操作成功！",{
                title: 'crm提示'
            })

            //向后台发送ajax请求
            $.ajax({
                //编写json格式，设置属性和值
                url:myUrl,
                contentType:"application/json;charset=utf-8",
                data:JSON.stringify(data.field),
                dataType:"text",
                type:"post",
                async:false,
                success:function (data){
                    //服务器端成功响应的json数据，进行解析
                    console.log(data)
                },
                end:parent.location.reload()
            })
            return false;
        });

        // //监听添加
        // form.on('submit(update)', function(data){
        //     layer.alert("恭喜你，修改成功！",{
        //         title: 'crm提示'
        //     })
        //     //向后台发送ajax请求
        //     $.ajax({
        //         //编写json格式，设置属性和值
        //         url:myUrl,
        //         contentType:"application/json;charset=utf-8",
        //         data:JSON.stringify(data.field),
        //         dataType:"text",
        //         type:"post",
        //         success:function (data){
        //             //服务器端成功响应的json数据，进行解析
        //             console.log(data)
        //         }
        //     })
        //     end:parent.location.reload()
        //     return false;
        // });
    });
    //地址
    function jg(){
        alert($("#province").val()+$("#city").val()+$("#district").val());
    }
</script>
</body>
</html>